package com.wjf.wjfaiagent.rag;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 创建基于内存的向量存储
 */
@Configuration
@Slf4j
public class SimpleVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Resource MyTokenTextSplitter myTokenTextSplitter;
    @Resource
    private MyKeywordEnricher myKeywordEnricher;
    @Bean
    public VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel){
        SimpleVectorStore vectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
        List<Document> allDocuments = loveAppDocumentLoader.loadMarkdowns();
//        List<Document> splitDocuments = myTokenTextSplitter.splitCustomized(allDocuments);
//        vectorStore.add(splitDocuments);
        // 使用关键字增强器为文档生成补充信息
//        List<Document> enrichDocuments = myKeywordEnricher.enrichDocuments(allDocuments);
        vectorStore.add(allDocuments);
        return vectorStore;
    }
}
